package com.jimet.utils.mail;

import java.util.Vector;

import com.jimet.server.JimetConfiguration;

public class MailerThread extends Thread{

	private Mailer mail;
	private Vector<String> receivers;
	private String smtpUser;
	private String smtpPwd;
	private long sleepTimeout;
	
	public MailerThread(Mailer pMail, Vector<String> pReceivers) {
		this.mail = pMail;
		this.receivers = pReceivers;
		this.smtpUser 	= JimetConfiguration.getString("SMTP.USERNAME");
		this.smtpPwd	= JimetConfiguration.getString("SMTP.PASSWORD");		
		this.sleepTimeout	= 0;
	}
	
	public MailerThread(Mailer pMail, String pReceiver) {
		this.mail = pMail;
		this.receivers = new Vector<String>();
		this.receivers.add(pReceiver);
		this.smtpUser 	= JimetConfiguration.getString("SMTP.USERNAME");
		this.smtpPwd	= JimetConfiguration.getString("SMTP.PASSWORD");	
		this.sleepTimeout	= 0;
	}
	
	public MailerThread( Mailer pMail ) {
		this.mail 		= pMail;
		this.smtpUser 	= JimetConfiguration.getString("SMTP.USERNAME");
		this.smtpPwd	= JimetConfiguration.getString("SMTP.PASSWORD");	
		this.sleepTimeout	= 0;
	}
	
	public MailerThread( Mailer pMail , String smtpUser , String smtpPwd , long timeout ) {
		this.mail 		= pMail;
		this.smtpUser 	= smtpUser;
		this.smtpPwd	= smtpPwd;	
		this.sleepTimeout	= timeout;
	}
	
	public void run() {
		Thread.yield();
		try {
		if ( sleepTimeout > 0 )
			Thread.sleep(sleepTimeout);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		this.mail.sendMail(JimetConfiguration.getString("SMTP.HOSTNAME"), JimetConfiguration.getString("SMTP.PORT") , this.smtpUser  , this.smtpPwd );
	}
}
